package com.xqboss.apps.service.marketing;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xqboss.apps.domain.marketing.MarketingAirdropMaterial;
import com.xqboss.apps.dto.marketing.GetAirdropListDto;
import com.xqboss.apps.mapper.marketing.MarketingAirdropMaterialMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * <p>
 * 空投-材料(热豆/扳手...) 服务实现类
 * </p>
 *
 * @author 木鱼
 * @since 2024-02-22
 */
@Service
@Slf4j
public class MarketingAirdropMaterialService extends ServiceImpl<MarketingAirdropMaterialMapper, MarketingAirdropMaterial> {

    /**
     * 获取空投材料列表
     * @param params
     * @return
     */
    public List<MarketingAirdropMaterial> getAirdropMaterialList(GetAirdropListDto params) {
        LambdaQueryWrapper<MarketingAirdropMaterial> wp = new LambdaQueryWrapper<>();
        if (StrUtil.isNotBlank(params.getSearch())) {
            wp.like(MarketingAirdropMaterial::getReason, params.getSearch());
        }
        if (Objects.nonNull(params.getType())) {
            wp.eq(MarketingAirdropMaterial::getType, params.getType());
        }
        wp.orderByDesc(MarketingAirdropMaterial::getCreateTime);
        return this.list(wp);
    }
}